<template>
  <div class="assess">
    <Header></Header>
    <div class="assessMain">
      <p class="current-nav2">
        当前位置 :
        <router-link to="waitAssess2">首页</router-link>
        <i>></i>
        <a>{{planCompany}}应急预案评审</a>
        <i>></i>
        <a>评审意见汇总</a>
      </p>
      <div class="mianOut">
        <div class="mianInner1">
          <div class="assess-title1">
            <h3>评审意见汇总</h3>
          </div>
          <el-table ref="multipleTable" class="mt60" :data="data1">
            <el-table-column type="index" align="center" label="序号" width="150"></el-table-column>
            <el-table-column prop="createUser" label="评审专家" align="center" width="200"></el-table-column>
            <el-table-column prop="identity" label="身份" align="center">
              <template>组长</template>
            </el-table-column>
            <el-table-column label="形式评审" align="center">
              <template slot-scope="scope">
                <span v-if="scope.row.reviewType == 5">形式评审表</span>
                <span v-if="scope.row.reviewType == 6">要素评审表</span>
                <span v-if="scope.row.reviewType == 7">附件要素评审表</span>
                <span v-if="scope.row.reviewType == 8">评审意见表</span>
              </template>
            </el-table-column>
            <el-table-column label="操作" align="center" width="150">
              <template slot-scope="scope">
                <el-button class="detail-btn" @click="goDetail(scope.row.reviewType,scope.row.id)">
                  <i class="el-icon-search">修改</i>
                </el-button>
              </template>
            </el-table-column>
          </el-table>
          <div class="aBtnBox">
            <input type="button" value="发送企业" @click="sendData" />
          </div>
        </div>
      </div>
    </div>
    <Footer />
    <el-dialog title :visible.sync="ideaPop2" width="80%">
      <div class="ideaMain">
        <h2 class="ideaTitle">应急预案评审意见表</h2>
        <p class="comName" v-if="detailData4.length>0">单位名称：{{detailData4[0].companyName}}</p>
          <Table5 v-if="detailData4.length>0" :data='detailData4' :signImg='signImg4'  @sendRemark='acceptRemark' @sendSuggest='acceptSuggest'  @sendConsensus='acceptConsensus'   />
        <div class="clearfix">
          <a class="table_save" @click="savePersonAll">保存</a>
        </div>
      </div>
    </el-dialog>
    <el-dialog title :visible.sync="situationFlag" width="80%">
      <div class="ideaMain">
        <h2 class="ideaTitle">应急预案形式评审表</h2>
       <Table1 :data='detailData1' />
        <div class="clearfix">
          <a class="table_save" @click="saveData(5)">保存</a>
        </div>
      </div>
    </el-dialog>
    <el-dialog title :visible.sync="keyFlag" width="80%">
      <div class="ideaMain">
        <Table2 :data1='list1' :data2='list2' :data3='list3' />
        <div class="clearfix">
          <a class="table_save" @click="saveData(6)">保存</a>
        </div>
      </div>
    </el-dialog>
    <el-dialog title :visible.sync="addFlag" width="80%">
      <div class="ideaMain">
        <h2 class="ideaTitle">应急预案附件要素评审表</h2>
        <Table3 :data='detailData3' />
        <div class="clearfix">
          <a class="table_save" @click="saveData(7)">保存</a>
        </div>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import Table1 from '../examine2/common/table1'
import Table2 from '../examine2/common/table2'
import Table3 from '../examine2/common/table3'
import Table5 from '../examine2/common/table5'
import Header from "../common/header2";
import Footer from "../common/footer";
import config from "../../config.js";
export default {
  components: {
    Header,
    Footer,Table1,Table2,Table3,Table5
  },
  data() {
    return {
      planCompany: "",
      situationFlag: false,
      keyFlag: false,
      addFlag: false,
      ideaPop2: false,
      signImg1: "",
      signImg2: "",
      signImg3: "",
      signImg4: "",
      id1: "",
      remark: "",
      consensus: "",
      varname: "",
      radios: [1, 2, 3],
      data1: [],
      detailData1: [],
      detailData2: [],
      detailData3: [],
      detailData4: [],
      suggest: "",
       list1:[],
      list2:[],
      list3:[],
    };
  },
  mounted() {
    var arr = [1, 2, 3, 4];
    this.varname = localStorage.planname.split(".")[0];
    arr.map(item => {
      this.getData(item);
    });
    this.planCompany = localStorage.planCompany;
  },
  methods: {
      acceptSuggest(val){
      this.suggest=val
    },
     acceptRemark(val){
       this.remark=val
    },
      acceptConsensus(val){
       this.consensus=val
    },
    sendData() {
      let url =
        config.baseUrl +
        "bsReviewSendCompany/v1.0/company/sendinfo?planSummaryId=" +
        localStorage.planid +
        "&userId=" +
        localStorage.userid;
      this.$axios.get(url).then(res => {
        if (res.data.meta.success) {
          this.$router.push("waitAssess2");
        } else {
          this.$message.warning(res.data.meta.message);
        }
      });
    },
    saveData(n) {
      
      let list = [];
      if(n != 6){
          this['detailData'+(n-4)].map((item,index)=>{
            if(index < ( this['detailData'+(n-4)].length-2)){
                list.push({
                      id:item.id,
                      selectResult:item.result 
                })
            }
          })
         
        }else{
          var arr=[1,2,3]
          for(var i in arr){
            this['list'+arr[i]].map((item,idx)=>{
              if(idx < ( this['list'+arr[i]].length-2)){
                    list.push({
                          id:item.id,
                          selectResult:item.result 
                    })
                }
              })
          }
        }

      console.log(JSON.stringify({
          mapList: list,
          planSummaryId: localStorage.planid,
          reviewType: n
        }))
    
      this.$axios
        .post(config.baseUrl + "bsReview/v1.0/review/updatesummary", {
          mapList: list,
          planSummaryId: localStorage.planid,
          reviewType: n
        })
        .then(res => {
          if (res.data.meta.success) {
            this.$message.success(res.data.meta.message);
            if (n == 5) {
              this.situationFlag = false;
            } else if (n == 6) {
              this.keyFlag = false;
            } else {
              this.addFlag = false;
            }
          } else {
            this.$message.warning(res.data.meta.message);
          }
        })
        .catch(response => {
          console.log(response);
        });
    },
    savePersonAll(id) {
      if (this.suggest == "" || this.consensus == "") {
        this.$message.warning("专家建议不能为空");
      } else {
        let url = config.baseUrl + "emergency/v1.0/review/edit";
        let param = {
          consensus: this.consensus,
          opinion: this.suggest,
          remarks: this.remark,
          reviewType: "8",
          id: this.id1,
          summaryTemplateName: localStorage.planname,
          planSummaryId: localStorage.planid,
          userId: localStorage.userid
        };
        this.$axios.post(url, param).then(res => {
          if (res.data.meta.success) {
            this.$message.success(res.data.meta.message);
            this.ideaPop2 = false;
          } else {
            this.$message.warning(res.data.meta.message);
          }
        });
      }
    },
    getData(n) {
      let url =
        config.baseUrl +
        "bsReview/v1.0/review/querySummaryType?planSummaryId=" +
        localStorage.planid;
      this.$axios.get(url).then(res => {
        if (res.data.meta.success) {
          this.data1 = res.data.data;
        } else {
          this.$message.warning(res.data.meta.message);
        }
      });
    },
    goDetail(n, id) {
      this.id1 = id;
      switch (n) {
        case "5":
          this.situationFlag = true;
          break;
        case "6":
          this.keyFlag = true;
          break;
        case "7":
          this.addFlag = true;
          break;
        default:
          this.ideaPop2 = true;
          break;
      }
      if (n == 8) {
        this.getPersonDetail(id);
      } else {
        this.getDetail(n);
      }
    },
    getPersonDetail(id) {
      let url = config.baseUrl + "emergency/v1.0/review/look?id=" + id;
      this.$axios.post(url).then(res => {
        if (res.data.meta.success) {
          this.signImg4 = res.data.data.autograph;
               console.log('00000')
          this.detailData4 = res.data.data.list;
     
          this.consensus = res.data.data.list[0].consensus;
          if (res.data.data.list[0].remarks) {
            this.remark = res.data.data.list[0].remarks;
          }
          this.signImg4 = res.data.data.url;
          this.suggest = res.data.data.list[0].opinion;
        } else {
          this.$message.warning(res.data.meta.message);
        }
      });
    },
    getDetail(n) {
      let url =
        config.baseUrl +
        "bsReview/v1.0/review/summaryInfoByType?planSummaryId=" +
        localStorage.planid +
        "&reviewType=" +
        n;
      this.$axios.get(url).then(res => {
        if (res.data.meta.success) {

if(res.data.data.list.length>0){
                    res.data.data.list.map((item,index)=>{
                      item.result=item.selectResult
                    })
                  }


 if(n==5){
                res.data.data.list.push({
                  reviewContent: res.data.data.url,
                  reviewItemOne: "评审专家签字",
                  reviewMethod: "",
                  tableType: "5",
                  flag:0,
                })
           }
           if(n==6){
              var obj = {
                    reviewContent:  res.data.data.url,
                    reviewItemOne: "评审专家签字",
                    reviewMethod: "",
                    tableType: "6",
                    flag:0,
                  }
                  this.list1 = res.data.data.list.splice(0,20)
                  this.list2 = res.data.data.list.splice(0,10)
                  this.list3 = res.data.data.list
               
                    this.list1.push({
                        reviewContent : '',
                        reviewItemOne: "注：“＊”代表应急预案的关键要素。",
                        reviewMethod: "",
                        tableType: "6",
                        flag:1,
                    })
                    this.list2.push({
                      reviewContent: '',
                      reviewItemOne: "注：“＊”代表应急预案的关键要素。如果专项应急预案作为综合应急预案的附件，综合应急预案已经明确的要素，专项应急预案可省略。",
                        reviewMethod: "",
                        tableType: "6",
                        flag:1,
                    })
                    this.list3.push({
                      reviewContent: '',
                      reviewItemOne: "注：“＊”代表应急预案的关键要素。现场处置方案落实到岗位每个人，可以只保留应急处置。",
                        reviewMethod: "",
                        tableType: "6",
                        flag:1,
                    })
                    this.list1.push(obj)
                    this.list2.push(obj)
                    this.list3.push(obj)    

           }

           if(n==7){
              res.data.data.list.push({
                   reviewContent: '',
                   reviewItemOne: "注：附件根据应急工作需要而设置，部分项目可省略。",
                    reviewMethod: "",
                    tableType: "6",
                    flag:1,
                })
                res.data.data.list.push({
                  reviewContent: res.data.data.url,
                  reviewItemOne: "评审专家签字",
                  reviewMethod: "",
                  tableType: "7",
                  flag:0,
                })
           }
          this["signImg" + (n*1-4)] = res.data.data.url;
          this["detailData" + (n*1-4)] = res.data.data.list;
        } else {
          this.$message.warning(res.data.meta.message);
        }
      });
    }
  }
};
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang='less'>
@import "../../../static/css/assess.less";
</style>
